package com.huluobo.a2206monthdemo.login;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.base.bean.UserBeanResult;
import com.huluobo.base.mvvm.BaseViewModel;
import com.huluobo.base.net.Const;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/8/31.
 */
public class LoginViewModel extends BaseViewModel<LoginRepo> {
    MutableLiveData<UserBeanResult> loginSuccess = new MutableLiveData<>();
    MutableLiveData<String> loginFailed = new MutableLiveData<>();

    public void login(String username, String password) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_USERNAME, username);
        map.put(Const.PARAM_PASSWORD, password);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.login(body, loginSuccess, loginFailed);
    }

    @Override
    protected LoginRepo createRepo() {
        return new LoginRepo();
    }
}
